<template>
	<div class="edit-popup">
		<popup ref="popupRef" :title="popupTitle" :async="true" width="90%" height="90%" @close="handleClose" cancelButtonText="关闭" confirmButtonText="">
			<div class="mt-[-28px]">
				<el-card class="!border-none" shadow="never">
					<el-card class="!border-none" shadow="never">
						<el-table size="large" v-loading="pager.loading" :data="pager.lists">
							<el-table-column label="用户" min-width="220">
								<template #default="{ row }">
									<div>账号：{{row.mobile}}</div>
									<div class="flex">邮箱：<text>{{row.auth_email==1?row.email:""}}</text></div>
									<div>邀请码：{{row.sn}}</div>
									<div>会员等级：{{row.vip_name}}</div>
								</template>
							</el-table-column>
							<el-table-column label="资金情况" min-width="130" show-tooltip-when-overflow>
								<template #default="{ row }">
									<div>
										总资产：{{row.user_money}}
									</div>
									<!-- <div>待释放：{{row.unused_money}}</div> -->
									<div>总充值：{{row.total_recharge}}</div>
									<div>总提现：{{row.total_withdraw}}</div>
									<div>充提差：
										<span v-if="row.total_recharge - row.total_withdraw < 0"
											class="text-danger font-bold">{{row.total_recharge - row.total_withdraw}}</span>
										<span
											v-if="row.total_recharge - row.total_withdraw >= 0">{{row.total_recharge - row.total_withdraw}}</span>
									</div>
									<div>总积分：{{row.user_point}}</div>
								</template>
							</el-table-column>
							<el-table-column label="团队情况" min-width="130" show-tooltip-when-overflow>
								<template #default="{ row }">
									<div>团队人数：{{row.team_num}}</div>
									<div>团队充值：{{row.team_recharge}}</div>
									<div>团队提现：{{row.team_withdraw}}</div>
								</template>
							</el-table-column>
							<el-table-column label="推广情况" min-width="130" show-tooltip-when-overflow>
								<template #default="{ row }">
									<div v-for="item in row.team_report" :key="item.id">
										{{item.level}}级人数：{{item.num}}/{{item.num_valid}}
									</div>
								</template>
							</el-table-column>
							<el-table-column label="质押情况" min-width="130" show-tooltip-when-overflow>
								<template #default="{ row }">
									<div>总订单：{{row.item_num}}</div>
									<div>今日订单：{{row.today_item_num}}</div>
									<div>总收益：{{row.total_income_invest}}</div>
									<div>总质押：{{row.total_invest}}</div>
								</template>
							</el-table-column>
							<el-table-column label="挖矿情况" min-width="130" show-tooltip-when-overflow>
								<template #default="{ row }">
									<div>总收益：{{row.mine.total_income}}</div>
									<div>今收益：{{row.mine.today_income}}</div>
								</template>
							</el-table-column>
							<el-table-column label="时间" min-width="240" show-tooltip-when-overflow>
								<template #default="{ row }">
									<div>注册时间：{{row.create_time}}</div>
									<div>注册IP：{{row.register_ip}}
										<span class="text-danger font-bold"
											v-if="row.register_ip != '' && row.register_ip_num>1">({{row.register_ip_num}})</span>
									</div>
									<div>注册国家：{{row.register_isp}}</div>
									<div>最后登录：{{row.login_time}}</div>
									<div>登录IP：{{row.login_ip}}
										<span class="text-danger font-bold"
											v-if="row.login_ip != '' && row.login_ip_num>1">({{row.login_ip_num}})</span>
									</div>
								</template>
							</el-table-column>
						</el-table>
						<div class="flex justify-end mt-4">
							<pagination v-model="pager" @change="getLists" />
						</div>
					</el-card>
				</el-card>
			</div>
		</popup>
	</div>
</template>

<script lang="ts" setup name="goodsEdit">
	import Popup from '@/components/popup/index.vue'
	import type { PropType } from 'vue'
	import { usePaging } from '@/hooks/usePaging'
	import { getUserList} from '@/api/consumer'

	defineProps({
		dictData: {
			type: Object as PropType<Record<string, any[]>>,
			default: () => ({})
		}
	})
	const emit = defineEmits(['success', 'close'])
	const popupRef = shallowRef<InstanceType<typeof Popup>>()


	// 弹窗标题
	const popupTitle = computed(() => {
		return '团队概况'
	})

	const queryParams = reactive({
		parent_sn: '',
		level: 0
	})

	//打开弹窗
	const open = () => {
		popupRef.value?.open()
	}

	// 关闭回调
	const handleClose = () => {
		emit('close')
	}

	const { pager, getLists, resetPage, resetParams } = usePaging({
		fetchFun: getUserList,
		params: queryParams
	})

	const setFormData = async (data : Record<any, any>) => {
		queryParams.level = data.level;
		queryParams.parent_sn = data.sn;
		
		getLists()
	}

	defineExpose({
		open,
		setFormData,
	})
</script>